Repository navigation
ASoC: SOF: Intel: hda: make sure the DMA is started/stopped by checking the RUN bit - #997
Conversation
plbossart
left a comment
There was a problem hiding this comment.
try to fix code style and need to fix assignment of the additional 'run' variable.
| SOF_HDA_CL_DMA_SD_INT_MASK, 0x0); | ||
|
|
||
| ret = | ||
| snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR, |
There was a problem hiding this comment.
it's better you have the function on the previous line. Try to see if you can fix the 80 char issue otherwise it's ok to not follow that rule.
|
|
||
| #define HDA_DSP_STREAM_RESET_TIMEOUT 300 | ||
| #define HDA_DSP_CL_TRIGGER_TIMEOUT 300 | ||
| #define HDA_DSP_STREAM_TRIGGER_TIMEOUT 300 |
There was a problem hiding this comment.
is this the same as legacy or Skylake, if yes add a comment. This looks like copy-paste and not an intentional definition
There was a problem hiding this comment.
In the Skylake, it is hard code. OK, I will add a comment to it.
| int sd_offset = SOF_STREAM_SD_OFFSET(hstream); | ||
| int ret, timeout = HDA_DSP_STREAM_RESET_TIMEOUT; | ||
| u32 val, mask; | ||
| u32 val, mask, run; |
| SOF_HDA_SD_CTL_DMA_START, 0); | ||
|
|
||
| ret = | ||
| snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR, |
There was a problem hiding this comment.
same, function on previous line
| int sd_offset = SOF_STREAM_SD_OFFSET(hstream); | ||
| int ret, timeout = HDA_DSP_STREAM_RESET_TIMEOUT; | ||
| u32 val, mask; | ||
| u32 val, mask, run; |
There was a problem hiding this comment.
run is not set anywhere, have you actually tested this code?
There was a problem hiding this comment.
the snd_sof_dsp_read_poll_timeout is a #define defined by @kv2019i :
set by line:
(val) = snd_sof_dsp_read(sdev, bar, offset); \
| ret = | ||
| snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR, | ||
| sd_offset, run, | ||
| ((run & SOF_HDA_SD_CTL_DMA_START) |
There was a problem hiding this comment.
how is run set in this patch?
There was a problem hiding this comment.
the snd_sof_dsp_read_poll_timeout is a #define defined by @kv2019i :
set by line:
(val) = snd_sof_dsp_read(sdev, bar, offset); \
00a4931 to
c6f9ad4
Compare
|
@plbossart Updated, with 2 lines exceed 80 chars. |
kv2019i
left a comment
There was a problem hiding this comment.
commit language: "to make sure the bit is right set" -> "to make sure the bit is set right"
kv2019i
left a comment
There was a problem hiding this comment.
Looks functionally good. A few editorial comments on commit message, doxygen description and line-wrapping.
| sd_offset, run, ((run & | ||
| SOF_HDA_SD_CTL_DMA_START) | ||
| == | ||
| SOF_HDA_SD_CTL_DMA_START), |
There was a problem hiding this comment.
@zhuyingjiang Having just "==" on the line is not readable anymore. I'd recommend not aligning to the opening brace and having a bit more space for the arguemnts. E.g. see call to snd_sof_dsp_read_poll_timeout() in hda-dsp.c:hda_dsp_core_power_down().
| * Timeout in us, for setting the stream RUN bit, during | ||
| * start/stop the stream. The time calculate the difference | ||
| * between write the RUN bit, and read the RUN bit to make | ||
| * sure it is set. |
There was a problem hiding this comment.
Suggestion:
""Timeout in us, for setting the stream RUN bit, during
start/stop the stream. The timeout expires if new RUN bit
value cannot be read back within the specified time.""
c6f9ad4 to
fdcea3e
Compare
|
Updated, thanks @kv2019i for the suggestions! |
kv2019i
left a comment
There was a problem hiding this comment.
Thanks! Almost there. One change req to the second commit still:
-During clear the stream status when setting HW parameters,
-the RUN bit must be read back as 0 after setting to 0, to
-make sure the stream is stopped.
+Beforing clearing stream statuses, ensure RUN bit update has taken
+effect by reading the value back.
Otherwise looks good to go!
fdcea3e to
dd3e3a9
Compare
|
@kv2019i Updated, thanks! |
kv2019i
left a comment
There was a problem hiding this comment.
Looks good now, thank you!
| sd_offset, run, ((run & | ||
| SOF_HDA_SD_CTL_DMA_START) | ||
| == 0x0), | ||
| HDA_DSP_REG_POLL_INTERVAL_US, |
There was a problem hiding this comment.
((run & SOF_HDA_SD_CTL_DMA_START) == 0x0), is a lot for a parameter, it's always better to define the variable on an earlier line e.g.
run_value = !(run &SOF_HDA_SD_CTL_DMA_START)
This can be fixed incrementally.
There was a problem hiding this comment.
agree with @lgirdwood please add an intermediate variable and simplify this.
There was a problem hiding this comment.
@lgirdwood @plbossart @kv2019i
The snd_sof_dsp_read_poll_timeout is a macro #define, not a really function, if using predefined variable as @lgirdwood suggested, the result should be not the same. Because the #define need first get the value of "run", and then the run & SOF_HDA_SD_CTL_DMA_START can be calculated.
@kv2019i Do you agree?
Another solution maybe define a macro for run & SOF_HDA_SD_CTL_DMA_START, as:
1):
#define RUN_VALUE ((run) & SOF_HDA_SD_CTL_DMA_START)
and use RUN_VALUE == SOF_HDA_SD_CTL_DMA_START and RUN_VALUE == 0 as the parameter.
or
2):
#define RUN_DMA_START (((run) & SOF_HDA_SD_CTL_DMA_START) == SOF_HDA_SD_CTL_DMA_START)
#define RUN_DMA_STOP (((run) & SOF_HDA_SD_CTL_DMA_START) == 0x0)
and use as:
ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,
sd_offset, run, RUN_DMA_START,
HDA_DSP_REG_POLL_INTERVAL_US,
HDA_DSP_STREAM_RUN_TIMEOUT);
What do you think?
There was a problem hiding this comment.
@zhuyingjiang I'm ok with the original as well -- this is used elsewhere in the codebase already. I'm not sure how much this helps readability to define more macros. Upto @plbossart and @lgirdwood who made the review comments.
One more option is to use a local variable to describe the mask only:
u32 dma_start = SOF_HDA_SD_CTL_DMA_START;
ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,
sd_offset, run, !(run & dma_start),
HDA_DSP_REG_POLL_INTERVAL_US,
But yeah, the improvement is limited.
There was a problem hiding this comment.
i like this update much better...
There was a problem hiding this comment.
OK, thanks @kv2019i , I will update with this solution.
lgirdwood
left a comment
There was a problem hiding this comment.
but please don't put large/complex params as function args.
| sd_offset, run, ((run & | ||
| SOF_HDA_SD_CTL_DMA_START) | ||
| == 0x0), | ||
| HDA_DSP_REG_POLL_INTERVAL_US, |
There was a problem hiding this comment.
agree with @lgirdwood please add an intermediate variable and simplify this.
| * start/stop the stream. The timeout expires if new RUN bit | ||
| * value cannot be read back within the specified time. | ||
| */ | ||
| #define HDA_DSP_STREAM_RUN_TIMEOUT 300 |
There was a problem hiding this comment.
still doesn't tell me where this value comes from, is this a hardware recommendation or 'same as the other drivers'
dd3e3a9 to
c07c69f
Compare
|
@plbossart @lgirdwood @kv2019i Updated, thanks! |
As per the HW recommendation, after setting the RUN bit (start as 1, stop as 0), software must read the bit back to make sure the bit is set right, before modifying related control registers/re-starting the DMA engine. Signed-off-by: Zhu Yingjiang <yingjiang.zhu@linux.intel.com>
…ream status Beforing clearing stream statuses, ensure RUN bit update has taken effect by reading the value back. Signed-off-by: Zhu Yingjiang <yingjiang.zhu@linux.intel.com>
c07c69f to
16dc2ab
Compare
As per the HW recommendation, after setting the RUN bit (start as 1, stop as 0), software must read the bit back to make sure the bit is right set, before modifying related control registers/re-starting the DMA engine.